package com.action.h5;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bean.ResponseBean;
import com.pojo.Jiedairen;
import com.pojo.Zixun;
import com.service.JiedairenService;
import com.service.ZixunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 咨询留言操作
 * @author Liao
 */
@RestController
@RequestMapping("/h5")
public class Zixunh5Action {
    @Autowired
    ZixunService zixunService;
    @Autowired
    JiedairenService jiedairenService;
    /**
     * 添加留言信息
     * @param zixun
     * @return
     */
    @PostMapping("/zixunadd")
    public ResponseBean add(@RequestBody Zixun zixun){
        if(zixun.getZxname()==null){
            return  ResponseBean.error("请填写咨询人");
        }
        if(zixun.getZxphone()==null){
            return  ResponseBean.error("请填写手机号码");
        }
        zixun.setZxtime(new Date());
        boolean f=  zixunService.save(zixun);
        if(f){
            return ResponseBean.ok("新增成功");
        }else{
            return ResponseBean.error("添加失败");
        }
    }

    /**
     * 查询接待人
     * @param id
     * @return
     */
    @RequestMapping("/getLaoshi")
    public ResponseBean getLaoshi(String id){
        Jiedairen jiedairen = jiedairenService.getById(id);
        if(jiedairen!=null){
            return  new ResponseBean(200,"查询成功",jiedairen);
        }else{
            return  ResponseBean.error("没有数据");
        }
    }

}
